package puzzle.projecteuler.p100;

import java.util.HashMap;
import java.util.Map;

public class Problem017 {

	/**
	 * @param args
	 */
	public static void main(String[] args) {

		String str = "";
		for (int i = 1; i <= 1000; i ++) {
			
			str += string(i);
		}
		System.out.println(str.replaceAll("\\s+", "").length());
	}
	
	private static Map<Integer, String> map = new HashMap<Integer, String>();
	static {
		map.put(0, "");
		map.put(1, "one");
		map.put(2, "two");
		map.put(3, "three");
		map.put(4, "four");
		map.put(5, "five");
		map.put(6, "six");
		map.put(7, "seven");
		map.put(8, "eight");
		map.put(9, "nine");
		map.put(10, "ten");
		map.put(11, "eleven");
		map.put(12, "twelve");
		map.put(13, "thirteen");
		map.put(14, "fourteen");
		map.put(15, "fifteen");
		map.put(16, "sixteen");
		map.put(17, "seventeen");
		map.put(18, "eighteen");
		map.put(19, "nineteen");
		map.put(20, "twenty");
		map.put(30, "thirty");
		map.put(40, "forty");
		map.put(50, "fifty");
		map.put(60, "sixty");
		map.put(70, "seventy");
		map.put(80, "eighty");
		map.put(90, "ninety");
	}

	public static String string(int n) {
		
		if (n<=0) {
			return "";
		} else if (n>=1 && n <= 20) {
			return map.get(n);
		} else if (n <= 99) {
			int a = (n/10) * 10;
			int b = n%10;
			return map.get(a) + " " + map.get(b);
		} else if (n <= 999) {
			int a = (n/100);
			int b = n%100;
			if (b == 0) {
				return map.get(a) + " hundred";
			} else {
				return map.get(a) + " hundred and " + string(b);
			}
		} else if (n == 1000) {
			return "one thousand";
		} else {
			return "";
		}
	}
}
